<template>
  <div class="app-container">
    <el-form :inline="true" label-width="80px">
      <el-form-item label="手机号码">
        <el-input
          v-model="queryParams.mobile"
          placeholder="手机号码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="昵称/姓名">
        <el-input
          v-model="queryParams.nickname"
          placeholder="昵称/姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="订单编号">
        <el-input
          v-model="queryParams.payno"
          placeholder="订单编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>


      <el-form-item label="购买时间">
        <el-date-picker
          v-model="startTime"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="postList">
      <el-table-column label="用户编号" align="center" prop="idNo"/>
      <el-table-column label="订单编号" align="center" prop="payno">
        <template slot-scope="scope">
          <el-popover placement="top-start" title="订单编号" width="250" trigger="hover">
            <div>{{scope.row.payno}}</div>
            <span slot="reference" v-if="scope.row.payno" >{{ scope.row.payno.substr(0,10)+'...' }}</span>
            <span slot="reference" v-else class="text-info">无</span>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column label="头像" align="center" prop="path">
        <template slot-scope="scope">
          <div>
            <el-popover placement="right" title="" trigger="click">
              <img :src="scope.row.path" alt="">
              <img slot="reference" :src="scope.row.path" alt="" style="max-height: 50px;max-width: 50px">
            </el-popover>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="用户昵称" align="center" prop="nickname"/>
      <el-table-column label="真实姓名" align="center">
        <template slot-scope="scope">
          <span :class="scope.row.realname?'':'text-warning'">{{ scope.row.realname?scope.row.realname:'未实名' }}</span>
        </template>
      </el-table-column>
      <el-table-column label="手机号" align="center" prop="mobile"/>
     <!-- <el-table-column label="线上推荐人" align="center">
        <template slot-scope="scope">
          <el-link v-if="scope.row.inviteNickname" title="查看详情" type="primary"
                   @click="referenceInfo(scope.row.inviteId)">{{scope.row.inviteNickname}}
          </el-link>
          <span v-else class="text-warning">暂无</span>
        </template>
      </el-table-column>
      <el-table-column label="线下推荐人" align="center">
        <template slot-scope="scope">
          <el-link v-if="scope.row.realInviteNickname" title="查看详情" type="primary"
                   @click="referenceInfo(scope.row.realInviteId)">{{scope.row.realInviteNickname}}
          </el-link>
          <span v-else class="text-warning">暂无</span>
        </template>
      </el-table-column>-->
      <el-table-column label="购买数量" align="center" prop="number"/>
      <el-table-column label="支付金额" align="center" prop="totalamount">
        <template slot-scope="scope">
          <span>{{formatCurrency(scope.row.totalamount) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="购买时间" align="center">
        <template slot-scope="scope">
          <span>{{ dateFormat(scope.row.createtime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="支付状态" align="center" prop="status" :formatter="payFormat">
        <template slot-scope="scope">
          <span v-if="scope.row.status===0" class="text-warning">{{ payFormat(scope.row) }}</span>
          <span v-else-if="scope.row.status===9" >{{ payFormat(scope.row) }}</span>
          <span v-else class="text-info">线下支付</span>
        </template>
      </el-table-column>

      <el-table-column label="购买源" align="center" prop="source" :formatter="sourceFormat"/>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <el-dialog :title="title" :visible.sync="userInfoOpen" width="600px">
      <el-form ref="form" label-width="150px">
        <el-form-item label="用户编号:">
          {{user.idNo}}
        </el-form-item>
        <el-form-item label="昵称:">
          {{user.nickname}}
        </el-form-item>
        <el-form-item label="真实姓名:">
          <span :class="user.realName?'':'text-warning'">{{ user.realName?user.realName:'未实名' }}</span>
        </el-form-item>
        <el-form-item label="手机号码:">
          {{user.mobile}}
        </el-form-item>
        <el-form-item label="角色:">
          {{roleFormat(user)}}
        </el-form-item>
        <el-form-item label="性别:">
          {{genderFormat(user)}}
        </el-form-item>
        <el-form-item label="创建时间:">
          {{ dateFormat(user.createtime) }}
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
  import {listCarBuyLog} from "@/api/maker/buy";
  import {list as userList} from "@/api/maker/user";

  export default {
    data() {
      return {
        startTime: '',
        // 遮罩层
        loading: false,
        // 总条数
        total: 0,
        // 岗位表格数据
        postList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        userInfoOpen: false,
        // 状态数据字典
        statusOptions: [],
        roleOptions: [],
        sourceOptions: [],
        genderOptions:[],
        payOptions:[],
        options: [],
        // 查询参数
        user: {},
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          mobile: undefined,
          nickname: undefined,
          startTime: undefined,
          endTime: undefined,
          payno: undefined,
        },
        form: {},
        rules: {}
      };
    },
    created() {
      this.getDicts("sys_user_sex").then(response => {
        this.genderOptions = response.data;
      });
      this.getDicts("yy_user_role").then(response => {
        this.roleOptions = response.data;
      });
      this.getDicts("yy_maker_source").then(response => {
        this.sourceOptions = response.data;
      });
      this.getDicts("yy_pay_status").then(response => {
        this.payOptions = response.data;
      });
      this.getList();
    },
    methods: {
      payFormat(row, column) {
        return this.selectDictLabel(this.payOptions, row.status);
      },
      genderFormat(row, column) {
        return this.selectDictLabel(this.genderOptions, row.gender);
      },
      roleFormat(row,column){
        return this.selectDictLabel(this.roleOptions, row.role);
      },
      referenceInfo(userId) {
        this.title = '用户详情';
        userList({userId: userId}).then(response => {
          this.userInfoOpen = true;
          this.user = response.rows[0];
        });
      },
      getList() {
        this.loading = true;
        listCarBuyLog(this.queryParams).then(response => {
          this.postList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      handleQuery() {
        if (this.startTime) {
          this.queryParams.startTime = this.startTime[0] + " 00:00:00";
          this.queryParams.endTime = this.startTime[1] + " 23:59:59";
        } else {
          this.queryParams.startTime = null;
          this.queryParams.endTime = null;
        }
        this.queryParams.pageNum = 1;
        this.getList();
      },
      sourceFormat(row, column) {
        return this.selectDictLabel(this.sourceOptions, row.source);
      }
    }
  }
</script>

<style scoped>

</style>
